perm filename FNGSER.MID[NET,MRC]3 blob sn#347763 filedate 1978-04-07 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00004 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	TITLE FNGSER
C00004 00003	Initialize the world
C00006 00004	FINGER over a PTY
C00009 ENDMK
C⊗;
TITLE FNGSER
SUBTTL Definitions

; Mark Crispin, SU-AI, April 1978

; Assembly switches

IFNDEF SVRSKT,SVRSKT==117		; default listen socket
IFNDEF PDLLEN,PDLLEN==50		; stack length

; AC definitions.  0→3 are used by NETWRK

X=4 ? A=5 ? B=6 ? P=17

; SAIL system bit definitions

IMPBIT==001000,,			; IMP TTY
FCS==   000020,,			; full character set mode
FULTWX==000004,,			; no echo

ECHOFF:	001400,,(FULTWX)		; echo off TTYSET command word
TERMID:	'TERMID				; for spies to see where we are
CORBEG==.				; start of initialized core storage
TERSTR:	BLOCK 10.			; console location string
PDL:	BLOCK PDLLEN			; stack
COREND==.-1				; end of initialized storage
SUBTTL Initialize the world

FNGSER:	JFCL
	RESET
	MOVE ['FNGSER]
	SETNAM
	SETZM CORBEG
	MOVE [CORBEG,,CORBEG+1]
	BLT COREND
	MOVE P,[PDL(-PDLLEN)]
	MOVEI [DEBREAK ? JRST SUICID]
	MOVEM JOBAPR
	CLKINT 5.*60.*60.		; must die if around too long
	OUTSTR [ASCIZ/FNGSER started
/]

; Listen for a connection on our socket

	MOVEI SVRSKT
	MOVEM LSNSKT
	PUSHJ P,LISTEN

; Set up terminal id for interested spies

	MOVEI TERMID
	MOVEM JOBVER

; Log the connection

	OUTSTR [ASCIZ/Connected to /]
	PUSHJ P,MAPHST			; map in host table
	MOVE HOST
	PUSHJ P,HSTNUM			; get HDB
	 JFCL				; sorry about errors
	MOVEI A,(1)			; host name
	HRLI A,440700
	SKIPA X,[440700,,TERSTR]
CPYHST:	 IDPB B,X
	ILDB B,A
	JUMPN B,CPYHST
	HLRZ A,1			; pointer to system name
	MOVE B,(A)			; get system name
	MOVE A,FSOCKT			; and ICP socket
	CAMN B,[ASCII/TIP/]		; on a TIP?
	 TRNE A,177774			; just paranoia; make sure a TIP port
	  JRST NOTTIP
	MOVEI B,"#
	IDPB B,X
	LSH A,-16.
	IDIVI A,8.			; ports are octal
	JUMPE A,1DIGTP
	ADDI A,"0 ? IDPB A,X
1DIGTP:	ADDI B,"0 ? IDPB B,X
NOTTIP:	PUSHJ P,SETANM			; set our job name
	PUSHJ P,UNMHST			; map out the host table
	OUTSTR TERSTR
	OUTSTR [ASCIZ/
/]
SUBTTL FINGER over a PTY

; Get a PTY, set it up, and log it in

	PTYGET A
	 EXIT
	MOVSI (A)
	IORM ECHOFF
	MOVSI B,(IMPBIT\FCS)
	PTSETL A			; set initial bits
	HRROI ECHOFF
	TTYSET				; echo off
	MOVEI B,5			; LOGIN
	PTJOBX A
	 EXIT

; Send command down PTY's throat

	MOVEI B,[ASCIZ/Finger /]
	PTWRS7 A			; send prelude
GETCMD:	PUSHJ P,NETICW
	CAIGE 177			; rubout or thing with parity bit?
	 CAIGE <" >			; or a control?
	  JRST GETCM1			; better check this out
	MOVE B,
	PTWR1W A			; ordinary character, send it
	JRST GETCMD
GETCM1:	CAIE ↑M				; CR is okay though
	 JRST GETCMD			; ignore other controls
	MOVE B,
	PTWR1W A			; send that
	PUSHJ P,NETICH			; eat the line feed
	PTRD1W A			; and the one from the PTY too!

; Get FINGER output from PTY

GETFNG:	PTRD1W A
	CAIN B,"↑			; start of ↑C saying dat's it?
	 JRST [	PTRD1W A
		CAIE B,"C		; is it really ↑C?
		 JRST [	MOVEI "↑	; oops!
			PUSHJ P,NETOCH
			JRST .+1]
		PUSHJ P,NETSND		; yes it was, force buffer out
		PUSHJ P,CLOSER
		EXIT]
	MOVEI (B)
	PUSHJ P,NETOCH			; send character to user
	JRST GETFNG

SUICID:	RESET ? EXIT

...LIT:	CONSTANTS

; Wonderful network routines

SVRRTS==-1				; include server routines
ERRTNS==-1				; include error routines
ERRHAN==-1				; include automagic error handling
ERRINS==<JRST SUICID>			; error instruction
HSTTAB==-1				; include host table magic
HSTSIX==-1				; and alias name kludge

.INSRT NETWRK[NET,MRC]

END FNGSER